# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html

import scrapy
from scrapy.loader import ItemLoader
from scrapy.loader.processors import MapCompose,TakeFirst

class ArticleItemLoader(ItemLoader):
    #自定义itemloader
    default_output_processor = TakeFirst()

class MyprojectItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    title = scrapy.Field()
    link = scrapy.Field()
    desc = scrapy.Field()
    support = scrapy.Field()
    mp4_url = scrapy.Field()
    pass

def re_title(value):
    return "罗---"+value


class BaiduItem(scrapy.Item):
    title = scrapy.Field(
        input_processor = MapCompose(re_title)
    )
    url = scrapy.Field()
    create_time = scrapy.Field()
    fav_nums = scrapy.Field()

    def get_insert_sql(self):
        insert_sql = """
            insert into url(title, url, create_time,fav_nums)
            VALUES (%s, %s, %s, %s)
        """
        params = (self["title"], self["url"], self["create_time"], self["fav_nums"])
        return insert_sql, params
    pass

class BtsoPwItem(scrapy.Item):
    title = scrapy.Field()
    size = scrapy.Field()
    tag = scrapy.Field()
    desc = scrapy.Field()
    mp4_url = scrapy.Field()

    def get_insert_sql(self):
        insert_sql = """
            insert into btso(title,mp4_size,tag,mp4_url,mp4_desc)
            VALUES (%s, %s, %s, %s, %s)
        """
        params = (self["title"], self["size"], self["tag"], self["mp4_url"], self["desc"])
        return insert_sql, params
    pass

class PornhubItem(scrapy.Item):
    title = scrapy.Field()
    support = scrapy.Field()
    mp4_url = scrapy.Field()
    views =  scrapy.Field()
    html_url = scrapy.Field()

    def get_insert_sql(self):
        insert_sql = """
            insert into pornhub_japanese(title,support,mp4_url,views,html_url)
            VALUES (%s, %s, %s, %s, %s)
        """
        params = (self["title"], self["support"], self["mp4_url"],self["views"],self["html_url"])
        return insert_sql, params
    pass

class JrSearchItem(scrapy.Item):
    item_title = scrapy.Field()
    is_sucess = scrapy.Field()
    item_type = scrapy.Field()
    item_url = scrapy.Field()
    amount = scrapy.Field()
    collectedAmount = scrapy.Field()
    projectId = scrapy.Field()
    topLimit = scrapy.Field()

    def get_insert_sql(self):
        insert_sql = """
            insert into jr_search(item_title,is_sucess,item_type,item_url,amount,collectedAmount,projectId,topLimit)
            VALUES (%s, %s, %s, %s,%s, %s, %s, %s)
        """
        params = (self["item_title"], self["is_sucess"], self["item_type"],self["item_url"],self["amount"], self["collectedAmount"], self["projectId"],self["topLimit"])
        return insert_sql, params
    pass

class DoubanGroupDiscussionItem(scrapy.Item):
    group_name = scrapy.Field()
    discussion_title = scrapy.Field()
    discussion_url = scrapy.Field()

    def get_insert_sql(self):
        insert_sql = """
            insert into douban_discussion(group_name,discussion_title,discussion_url)
            VALUES (%s, %s, %s)
        """
        params = (self["group_name"], self["discussion_title"], self["discussion_url"])
        return insert_sql, params
    pass

class Dj_Jd_Item(scrapy.Item):
    items_name = scrapy.Field()
    items_status = scrapy.Field()
    items_num = scrapy.Field()
    items_per = scrapy.Field()
    items_type = scrapy.Field()

    def get_insert_sql(self):
        insert_sql = """
            insert into dj_jd(items_name,items_status,items_num,items_per,items_type)
            VALUES (%s, %s, %s, %s, %s)
        """
        params = (self["items_name"], self["items_status"], self["items_num"], self["items_per"], self["items_type"])
        return insert_sql, params
    pass

class leetcode_huaren_Item(scrapy.Item):
    items_name = scrapy.Field()
    items_content = scrapy.Field()


    def get_insert_sql(self):
        insert_sql = """
            insert into leetcode_huaren_com(name,content)
            VALUES (%s, %s)
        """
        params = (self["items_name"], self["items_content"])
        return insert_sql, params
    pass